package com.charon.module.music.mercuty.web;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.charon.common.result.Result;
import com.charon.common.util.StringUtils;
import com.charon.common.util.wangyi.WYHandler;
import com.charon.common.util.wangyi.entity.WYSongListEntity;
import com.charon.module.music.mercuty.service.MercutyMusicService;

import net.sf.json.JSONObject;

@RequestMapping("/mercury")
@Controller
public class MercutyMusicController {
	
	@Autowired
	MercutyMusicService mms;
	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	
	/**
	 * 主页视图
	 * @return
	 */
	/*@RequestMapping("")
	public String mercuryHome(){
		return "redirect:/mercury/mercury.html";
	}*/
	
	@RequestMapping("")
	public String mercuryHome(){
		return "redirect:/mercury/lock.html";
	}
	
	@RequestMapping("lockVer")
	@ResponseBody
	public Result<String> lock(Integer date){
		logger.debug("info",date);
		Result<String> rs=new Result<String>();
		if(StringUtils.isEmpty(date)){
			rs.setData("GG");
			return rs;
		}else if(date==1118){
			
			rs.setData("ok");
			return rs;
		}
		rs.setData("GG");
		logger.debug("info",rs);
		return rs;
	}
	
	
/*	失效
 * 
 * @RequestMapping("getSongURL")
	@ResponseBody
	public String getSongURL(String songID){
		logger.debug("info",songID);
		JSONObject list = mms.getSongList(songID);
		logger.debug("info",list.toString());
		return list.toString();
	}*/
	
	@RequestMapping("getSongList")
	@ResponseBody
	public String getSongList(String listID){
		logger.info(listID);
		JSONObject list = mms.getSongList(listID);
		logger.debug("info",list.toString());
		return list.toString();
	}
	
	/**
	 * 根据用户ID获取歌单列表
	 * @param userId
	 * @return
	 */
	@RequestMapping("getSongLists")
	@ResponseBody
	public Result<List<WYSongListEntity>> getSongLists(Integer userId){
		Result<List<WYSongListEntity>> result = new Result<List<WYSongListEntity>>();
		result.setStatus(0+"");
		result.setMessage("成功");
		logger.debug("info",userId);
		List<WYSongListEntity> lists = mms.getUserSongLists(userId+"");
		result.setData(lists);
		return result;
	}
	
	/**
	 * 搜索功能
	 * @param keyWords
	 * @param limit
	 * @param offset
	 * @param type 
	 * @return
	 */
	@RequestMapping("searchByType")
	@ResponseBody
	public Result<String> searchByType(@RequestParam(required=true)String keyWords,
			@RequestParam(required=false)Integer limit,
			@RequestParam(required=false)Integer offset,
			@RequestParam(required=false)Integer type){
		logger.info(keyWords);
		JSONObject object = mms.searchByType(keyWords, limit+"", offset+"", type+"");
		Result<String> result = new Result<String>();
		if(null==object){
			result.setStatus(0+"");
			result.setMessage("暂无数据");
			return result;
		}
		result.setStatus(0+"");
		result.setMessage("成功");
		result.setData(object.toString());
		logger.info(result.toString());
		return result;
	}
	
	@RequestMapping("getLrc")
	@ResponseBody
	public Result<JSONObject> getLrc(Integer songID){
		Result<JSONObject> result = new Result<JSONObject>();
		logger.info(songID.toString());
		JSONObject lrc = mms.getLrc(songID+"");
		result.setStatus(0+"");
		result.setMessage("成功");
		result.setData(lrc);
		if(lrc!=null){
			logger.info(lrc.toString());
		}
		return result;
	}
	
	@RequestMapping("songCollect")
	@ResponseBody
	public Result<String> songCollect(Integer songID,Integer type){
		Result<String> result = new Result<String>();
		result.setStatus(0+"");
		result.setMessage(mms.songCollect(songID, type));
		result.setData(null);
		return result;
	}
	
	@RequestMapping("songLike")
	@ResponseBody
	public Result<String> songLike(Integer songID,Integer type){
		Result<String> result = new Result<String>();
		result.setStatus(0+"");
		result.setMessage(mms.songLike(songID, type));
		result.setData(null);
		return result;
		
	}
	
	@RequestMapping("songSick")
	@ResponseBody
	public Result<String> songSick(Integer songID,Integer type){
		Result<String> result = new Result<String>();
		result.setStatus(0+"");
		result.setMessage(mms.songSick(songID, type));
		result.setData(null);
		return result;
	}
	
	@RequestMapping("checkSong")
	@ResponseBody
	public Result<String> checkSong(Integer songID){
		Result<String> result = new Result<String>();
		String data = mms.checkSong(songID+"");
		result.setStatus(0+"");
		result.setMessage("成功");
		result.setData(data);
		return result;
	}
	
	/**
	 * @Description: 获取热门歌单 
	 * @Author charon [248135724@qq.com]
	 * @Date:   2018年11月15日 下午8:34:20 
	 * @return
	 */
	@RequestMapping("getHighQuality")
	@ResponseBody
	public Result<JSONObject> getHighQuality(Integer limit,@RequestParam(required=false)String updateTime){
		if(StringUtils.isEmpty(updateTime)){
			updateTime=null;
		}
		JSONObject data = mms.getHighQuality(limit+"",updateTime);
		Result<JSONObject> result = new Result<JSONObject>();
		result.setStatus(0+"");
		result.setMessage("成功");
		result.setData(data);
		return result;
	}
	
	/**
	 * @Description: 获取网友精选歌单
	 * @Author charon [248135724@qq.com]
	 * @Date:   2018年11月15日 下午8:35:22 
	 * @return
	 */
	@RequestMapping("getNetFriendLists")
	@ResponseBody
	public Result<String> getNetFriendLists(Integer limit){
		String data = mms.getNetFriendLists(limit+"");
		Result<String> result = new Result<String>();
		result.setStatus(0+"");
		result.setMessage("成功");
		result.setData(data);
		return result;
	}
	
	@RequestMapping("getSongInfo")
	@ResponseBody
	public Result<JSONObject> getSongInfo(Integer songID){
		logger.info(songID.toString());
		JSONObject data = mms.getSongInfo(songID+"");
		Result<JSONObject> result = new Result<JSONObject>();
		result.setStatus(0+"");
		result.setMessage("成功");
		result.setData(data);
		logger.debug("info",result.toString());
		return result;
	}
	
}
